<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <comp-a></comp-a>

    <script type="text/template" id="temp">
      <div>comp-a <hr> <comp-b></comp-b> </div>
    </script>

  </div>

  <script>

    var compb = {
      data() {
        return {
          count: 1
        }
      },
      inject:['msg'],
      template: '<h1 @click="handleClick">comp-b-{{msg}}</h1>',
      methods: {
        handleClick() {
          alert('comp-b')
        }
      }
    };

    var vm = new Vue({
      el: "#app",
      data: {
        msg: "来自根组件的数据"
      },
      provide() {
        return {
          msg: this.msg
        }
      },
      components: {
        'comp-a': {
          template: '#temp',
          components: {
            'comp-b': compb
          }
        }
      }
    })

  </script>

</body>

</html>